package cn.jietuo.juc.c_010_interview3;

import java.util.concurrent.locks.LockSupport;

/**
 * @author zhangx & jietuo_zx@163.com
 * @version 1.0
 * @date 2020/5/8
 * @description:
 */
public class T01_LockSupport {

    static char[] str1 = new char[]{'1', '2', '3', '4', '5', '6', '7', '8'};
    static char[] str2 = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};

    static Thread t1 = null, t2 = null;

    public static void main(String[] args) {

         t1 = new Thread(() -> {
            for (int i = 0; i < str1.length; i++) {
                System.out.println(str1[i]);
                // 叫醒T2
                LockSupport.unpark(t2);
                // 阻塞自己T1
                LockSupport.park();

            }

        });

         t2 = new Thread(() -> {
            for (int i = 0; i < str2.length; i++) {
                // 阻塞自己T2
                LockSupport.park();
                System.out.println(str2[i]);
                // 叫醒T1
                LockSupport.unpark(t1);
            }
        });

        t1.start();
        t2.start();
    }
}
